/**
 * 
 */
package com.kun;


import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.test.context.junit4.SpringRunner;

import com.kun.config.EntityRedisSerializer;
import com.kun.entity.Book;
import com.kun.entity.User;
import com.kun.service.UserService;
import com.kun.util.StaticPageGenerateUtil;

/**
 * @author KM
 * 2018年3月16日
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class TEST {
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private SetOperations<String, Object> setOperations;
	
	@Autowired
	private RedisTemplate<String, Object> redisTemplate;

	@Test
	public void test() {
//		User user = userService.selectByPrimaryKey("1");
//		Map<String,Object> map = new HashMap<String,Object>();
//		System.out.println(user.toString());
//		map.put("user", user);
//		String path = "/html/zaResult";
//		String msg = StaticPageGenerateUtil.generatePage("za", path, map);
//		System.out.println(msg);
	}
	
	@Test
	public void test1() {
		redisTemplate.setValueSerializer(new StringRedisSerializer());
		//redisTemplate.setValueSerializer(new EntityRedisSerializer());
		redisTemplate.opsForValue().set("post", "0");
		
//		redisTemplate.opsForValue().increment("post", 1);
//		System.out.println("加一");
//		System.out.println(redisTemplate.opsForValue().get("post"));
//		
//		
//		redisTemplate.opsForValue().increment("post", 2);
//		System.out.println("加二");
//		System.out.println(redisTemplate.opsForValue().get("post"));
//		
//		
//		redisTemplate.opsForValue().increment("post", 5);
//		System.out.println("加五");
//		System.out.println(redisTemplate.opsForValue().get("post"));
		
		
		redisTemplate.opsForValue().increment("post", -1);
		System.out.println("减一");
		System.out.println(redisTemplate.opsForValue().get("post"));
		
		redisTemplate.opsForValue().increment("post", -2);
		System.out.println("减2");
		System.out.println(redisTemplate.opsForValue().get("post"));
//		Object ob = setOperations.pop("uH27jAr" + "USER_BOOK_SET");
//		System.out.println(ob);
//		
//		Set<Object> lb = setOperations.members("uH27jAr" + "USER_BOOK_SET");
//		System.out.println(lb.size());
//		for (Object object : lb) {
//			Book b = (Book)object;
//			System.out.println(b.getBookname());
//		}
		//Set<Object> lb = setOperations.members("uH27jAr" + "USER_BOOK_SET");
//		System.out.println(setOperations.members("uH27jAr" + "USER_BOOK_SET").size());
//		for (Object object : lb) {
//			setOperations.remove("uH27jAr" + "USER_BOOK_SET", object);
//		}
		
		//System.out.println(UUID.randomUUID().toString());
	}

}
